#include<malloc.h>
#include<iostream>
#include<vector>
using namespace std;

 struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
};

int treesize(struct TreeNode* root)
{
    if(root==NULL)
    {
        return 0;
    }
    return treesize(root->left)+treesize(root->right)+1;

}

void inorder(struct TreeNode* root,int *a,int *pi)
{
    if(root==NULL)return;
    inorder(root->left,a,pi);
    a[(*pi)++]=root->val;
    inorder(root->right, a,pi);
}

int* inorderTraversal(struct TreeNode* root, int* returnSize){
   *returnSize=treesize(root);
   int *a=(int*)malloc(*returnSize *sizeof(int));
   int pi=0;
   inorder(root,a,&pi);
   return a;
}